<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var num = 10;  //全局变量
        function fn() {
            var num = 20;  //函数内变量，只在函数内起作用，与全局变量不冲突
            num1 = 30;   //全局变量的另一种方式，直接赋值
            console.log(num);
        }
        console.log(num);
        fn();
    </script>
</head>


<body>

</body>

</html>